<template>
  <div class="user">
    <div class="user-left">
      <div class="user-img"><img :src="avatar" alt="" /></div>
      <!-- <p>{{ nickname }}</p> -->
      <p @click="user">个人中心</p>
      <p @click="mail">积分商城</p>
      <p @click="quit">退出</p>
    </div>
    <div class="user-right">
      <div class="top">
        <h4>商城</h4>
        <div class="jf">
            <p class="jf-integration">当前积分：{{ integration }}</p>
        </div>
      </div>
      <div class="user-body">
        <h1>商品列表</h1> </div>
      <div class="show-list">
        <div class="show-item" v-for="(item, index) in list" :key="index">
          <img :src="item.image">
          <p>{{ item.name }}</p>
          <div class="price">
            <p>{{ item.price }}积分</p>
            <button  @click="change()">兑换</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "user",
  data() {
    return {
      list: [],
    };
  },
  computed: {
    ...mapState({
      username: (state) => state.login.username,
      password: (state) => state.login.password,
      age: (state) => state.login.age,
      avatar: (state) => state.login.avatar,
      gender: (state) => state.login.gender,
      school: (state) => state.login.school,
      nickname: (state) => state.login.nickname,
      integration: (state) => state.login.integration,
      _id:(state) => state.login._id
    }),
  },
  created() {
    this.getFun();
  },
  methods: {
    async getFun() {
      const data = await this.yGet("/shop/shopList");
      if(data){
        this.list = data.data
      }
    },
       async change () {
      const data = await this.yPut('shop/exchange', {
          id: data.item._id,
      });
      if (data) {
        this.setUser('getUserInfo');
        this.$message({
          message: '恭喜你，兑换成功',
          type: 'success',
          duration: 1000,
          offset: '150'
        })
      }
    },
    quit() {
      this.$router.push({
        name: "Home",
      });
    },
    mail() {
      this.$router.push({
        name: "mail",
      });
    },
    user() {
      this.$router.push({
        name: "user",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.user {
  padding: 0;
  margin: 0;
  &-left {
    width: 500px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    background-color: #3d3b3b;
    margin: auto;
    padding-top: 100px;
    font-size: 35px;
    &-img {
      width: 50%;
      margin: auto;
    }
    p {
      width: 500px;
      height: 80px;
      padding-top: 45px;
      text-align: center;
      margin: auto;
    }
  }
  &-right {
    width: 960px;
    height: 100%;
    padding-top: 55px;
    margin: 0 auto;
    h4{
      font-size: 16px;
      font-weight: 400;
      color: #202020;
      line-height: 56px;
      text-align: left;
    }
  }
}
img {
  width: 175px;
  height: 175px;
  border-radius: 50%;
  margin-left: 175px;
}
.user-body{
  // font-size: 30px;
  margin-top: 270px;
  margin-left: 300px;
  width: 900px;
  h1{
      font-size: 25px;
      color: #333;
      padding-bottom: 20px;
      margin: 0 auto;
  }
}
.top {
    height: 70px;
    padding: 0 40px;
    background: #fff;
    -webkit-box-shadow: 5px 6px 4px rgba(213,209,209,.5);
    box-shadow: 5px 6px 4px rgba(213,209,209,.5);
    position: fixed;
    top: 0;
    left: 500px;
    right: 0;
    z-index: 9999;
}
.jf {
  width: 960px;
    height: 160px;
    background: url('https://by-image.oss-cn-shanghai.aliyuncs.com/yfront/static/user/mall/pic_beijing0_jifen.png') 100% 100%;
    margin: 46px auto;
    background-size: cover;
    display: flex;
    color: #fff;
    font-size: 30px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  &-integration{
    padding-top: 5%;
  }
}
.show-list{
  display: flex;
  margin-top: 150px;
  margin-left: 300px;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
      display: flex;
    width: 100%;
   
    img{
      width: 270px;
      height: 250px;
      border-radius: 0;
      margin-left: 0;
      padding-right:0px;
    }
}
.show-item {
    padding: 0 30px 50px 0;
    width: 30%;
}
.price{
  height: 30px;
  display: flex;
  justify-content: space-between;
}
button{
  color:#fff;
  background-color: #409EFF;
  border-radius:5px;
}
</style>